package com.atguigu.gulimall.order.vo;

import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


public class OrderConfirmVo {

    //收货地址
    @Setter
    @Getter
    List<MemberAddressVo> address;

    //所有选中的购物项
    @Setter
    @Getter
    List<OrderItemVo> items;

    //优惠券信息
    @Setter
    @Getter
    Integer integration;
    @Setter
    @Getter
    Map<Long,Boolean> hasStock;
//订单总价
//    BigDecimal totalPrice;

   public Integer getItemCount(){
      Integer sum = 0;
       if(items!=null){
           for (OrderItemVo item : items) {
              sum+=item.getCount();
           }
       }
       return sum;
   }


    public BigDecimal getTotalPrice() {
        BigDecimal sum = new BigDecimal("0");
        if(items!=null){
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));

                 sum = sum.add(multiply);
            }
        }
        return sum;
    }

//    BigDecimalmal payPrice;

    public BigDecimal getPayPrice() {


        return this.getTotalPrice();
    }

    //防重复下单
    @Getter @Setter
    String orderTokern;

    @Override
    public String toString() {
        return "OrderConfirmVo{" +
                "address=" + address +
                ", items=" + items +
                ", integration=" + integration +
                ", orderTokern='" + orderTokern + '\'' +
                '}';
    }
}
